import httpx

# 任务队列的链接地址
from celery_tasks.config import app
from user.models import RTHui

@app.task
def getHuilv():
    # 请求数据
    data = eval(httpx.get(
        'http://op.juhe.cn/onebox/exchange/currency?key=20b4bfafedccea7b5a7e0571ace2f0b3&from=USD&to=CNY').text)
    # 进行入库操作
    dateti = data['result'][0]['updateTime']
    RTHui.objects.create(
        date=dateti.split(' ')[0],
        time=dateti.split(' ')[1],
        json=data['result'][0]['exchange']
    )
    print(data)
